const Controller = require('../../core/controller/ApiController');
const {Route, HttpGet, HttpPost, HttpDelete, Middleware, filters} = require('../../../plugin/egg-decorator-router/lib');
const {ExceptionHandler} = require('../../../plugin/egg-controller-exception-handler/lib');

@Route('/api/admin/svcrecord')
class SvcRecordCtrl extends Controller {

    //搜索服务历史
    @HttpGet('/search')
    @ExceptionHandler()
    async searchRecord() {
        const rule = {
            begin: 'anyDate',
            end: 'anyDate',
            svc_item_id: 'int',
            status: 'int'
        };
        this.validate(rule, this.ctx.request.query);
        const query = this.ctx.request.query;
        this.result.data = await this.service.admin.svcrecord.main.searchRecord(query.begin, query.end, query.svc_item_id, query.status);
        return '查询成功'
    }

    //搜索服务项目列表
    @HttpGet('/svcitem/list')
    @ExceptionHandler()
    async searchSvcItemList() {
        this.result.data = await this.service.admin.svcrecord.main.searchSvcItemList();
        return '查询成功'
    }

    //服务历史查看详情
    @HttpGet('/:id')
    @ExceptionHandler()
    async viewDetail() {
        const rule = {
            id: 'int'
        };
        this.validate(rule, this.ctx.params);
        this.result.data = await this.service.admin.svcrecord.main.viewDetail(this.ctx.params.id);
        return '查询成功'
    }

    //服务历史详情编辑
    @HttpPost('/edit')
    @ExceptionHandler()
    async editDetail() {
        const rule = {
            svc_record_id: 'int',
            text_evalu: 'string',
            remark: 'string'
        };
        const body = this.ctx.request.body;
        this.validate(rule, body);
        await this.service.admin.svcrecord.main.editDetail(body.svc_record_id, body.text_evalu, body.remark);
        return '编辑成功'
    }

}

module.exports = SvcRecordCtrl;
